/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package appkasir;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Heri Setiyawan
 */
public class CKassir extends koneksi_access{
    public String idKasir,nmKasir,alamat,telepon,password;
    koneksi_access kon = new koneksi_access();
    
    public CKassir(){
      kon.setKoneksi();
    }
    
    public void setIdKasir(String value){
        idKasir = value;
    }
    
    public void setNamaKasir(String value){
        nmKasir = value;
    }
    
    public void setAlamat(String value){
        alamat = value;
    }
    
    public void setTlp(String value){
        telepon = value;
    }
    
    public void setPassword(String value){
        password = value;
    }
    
//    getter
    public String getIdKasir(){
        return idKasir;
    }
    
    public String getNamaKasir(){
        return nmKasir;
    }
    
    public String getAlamat(){
        return alamat;
    }
    
    public String getTlp(){
        return telepon;
    }
    
    public String getPassword(){
        return password;
    }
    
    public boolean Insert(){
        Boolean i = false;
        String sql = "insert into tbkasir values('"+idKasir
                +"','"+nmKasir+"','"+alamat+"','"
                +telepon+"','"+password+"')";
        Statement st;
        try{
            st = kon.conn.createStatement();
            st.executeUpdate(sql);
            i=true;
        }catch(Exception e){
            System.out.print(e);
        }
        return i;
    }
    
    public boolean find(){
        Boolean i = false;
        String sql = "select * from tbkasir where id_kasir='"+idKasir+"'";
        Statement st;
        try{
            st = kon.conn.createStatement();
            rst = st.executeQuery(sql);
            if(rst.next()){
                nmKasir = rst.getString("nama_kasir");
                alamat = rst.getString("almat");
                telepon = rst.getString("telp");
                password = rst.getString("pass");
            i=true;
            }
        }catch(Exception e){
            Logger.getLogger(CKassir.class.getName()).log(Level.SEVERE,null,e);
        }
        return i;
    }
    
     public boolean delete(){
        Boolean i = false;
        String sql="delete from tbkasir where id_kasir='"+
                idKasir+"'";
        try{
            kon.stt.executeUpdate(sql);
            i=true;
        }catch(Exception e){
            System.out.print(e.getMessage());
        }
        return i;
    }
     
     public boolean Update(){
        Boolean i = false;
        String sql = "update tbkasir set nama_kasir='"
                +nmKasir+"',almat='"+alamat+"',telp='"
                +telepon+"',pass='"+password
                +"' where id_kasir='"+idKasir+"'";
        Statement st;
        try{
            st = kon.conn.createStatement();
            st.executeUpdate(sql);
            i=true;
        }catch(Exception e){
            Logger.getLogger(CKassir.class.getName()).log(Level.SEVERE,null,e);
        }
        return i;
    }
     
     public DefaultTableModel getTabel(){
         String judul[] = {"ID KASIR",
             "NAMA KASIR","ALAMAT",
             "NO TELEPONE","PASSWORD"};
         String sql = "select * from tbkasir order by id_kasir";
         DefaultTableModel dtm = new DefaultTableModel(null,judul);
         try{
             kon.rst = kon.stt.executeQuery(sql);
             String Data[] = new String[5];
             while(kon.rst.next()){
                 Data[0] = kon.rst.getString(1);
                 Data[1] = kon.rst.getString(2);
                 Data[2] = kon.rst.getString(3);
                 Data[3] = kon.rst.getString(4);
                 Data[4] = kon.rst.getString(5);
                 dtm.addRow(Data);
             }
         }catch(Exception e){
             JOptionPane.showMessageDialog(null,"Table MOdel "+e);
         }
         return dtm;
     }
}
